<?php
$oUsers = UserHandler::getUsers();
$oUsergroups = UsergroupHandler::getUsergroups();

$oUserAccess = JobHandler::getUserAccess($_SESSION['iJobID'], true);
$oUsergroupAccess = JobHandler::getUsergroupAccess($_SESSION['iJobID']);

$oJob = JobHandler::getCurrentJob();
?>

<div class="hidden" id="layer_job_access" style="visibility: visible;">
<table class="boxborder" cellspacing="0">
	<tr>
		<td class="boxhandle" colspan="2"><?php print msg('Access') ?></td>
	</tr>
<?php
if (count($oUsergroups) > 0) {
	?>
	<tr>
		<td class="listtop center nowrap">
			<a href="javascript: showBox('job-usergroupadd'); layerHide('layer_job_access');"><img src="images/<?php print $_SESSION['oUserVars']['images'] ?>/usergroup-add.png" border="0"></a>
		</td>
		<td class="listtop"><?php print msg('Usergroups') ?></td>
	</tr>
	<?php
	foreach ($oUsergroupAccess as $iUsergroup => $oAccess) {
		?>
		<tr>
			<td class="listentity center nowrap">
				<a href="javascript: showBox('job-usergroupdelete', 'iUsergroup=<?php print $iUsergroup ?>'); layerHide('layer_job_access');"><img src="images/<?php print $_SESSION['oUserVars']['images'] ?>/usergroup-delete.png" border="0"></a>
				<a href="javascript: showBox('job-usergroupchange', 'iUsergroup=<?php print $iUsergroup ?>'); layerHide('layer_job_access');"><img src="images/<?php print $_SESSION['oUserVars']['images'] ?>/usergroup-change.png" border="0"></a>
			</td>
			<td class="listentity">
				<img src="images/<?php print $_SESSION['oUserVars']['images'] ?>/usergroup.png">
				<a href="index.php?sView=usergroup-view&iUsergroup=<?php print $iUsergroup ?>"><?php print $oUsergroups[$iUsergroup]->sName ?></a></td>
			</td>
		</tr>
		<?php
	}
}
?>
	<tr>
		<td class="listtop center">
			<a href="javascript: showBox('job-useradd'); layerHide('layer_job_access');"><img src="images/<?php print $_SESSION['oUserVars']['images'] ?>/user-add.png" border="0"></a>
		</td>
		<td class="listtop"><?php print msg('Users') ?></td>
	</tr>
<?php
foreach ($oUserAccess as $iUser => $oAccess) {

	?>
	<tr>
		<td class="listentity center nowrap">
	<?php
	if ($iUser != $_SESSION['rid'] && $iUser != $oJob->iOwner) {
		?>
			<a href="javascript: showBox('job-userdelete', 'iUser=<?php print $iUser ?>'); layerHide('layer_job_access');"><img src="images/<?php print $_SESSION['oUserVars']['images'] ?>/user-delete.png" border="0"></a>
			<a href="javascript: showBox('job-userchange', 'iUser=<?php print $iUser ?>'); layerHide('layer_job_access');"><img src="images/<?php print $_SESSION['oUserVars']['images'] ?>/user-change.png" border="0"></a>
		<?php
	}
	else {
		print '&nbsp;';
	}
	?>
		</td>
		<td class="listentity">
			<img src="images/<?php print $_SESSION['oUserVars']['images'] ?>/user.png">
			<a href="index.php?sView=user-view&iUser=<?php print $iUser ?>"><?php print $oUsers[$iUser]->sUser ?></a>
	<?php
	if ($oJob->iOwner == $iUser) {
		print '<span class="small">('.msg('owner').')</span>';
	}
	?>
		</td>
	</tr>
	<?php
}
?>
	<tr>
		<td class="boxbody center" colspan="2">
			<input type="button" value="<?php print msg('Cancel') ?>" onClick="layerHide('layer_job_access');">
		</td>
	</tr>
</table>
</div>
